{extends file="../home.html"}
{block name="title"}{$head_title}{/block}
{block name="css"}
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/front/front_css/detail_page.css?version={$version}"/>
{/block}
{block name="content"}
	<div class="deliver-header">
		<a href="javascript:void(0)" class="clearfix">
			<i class="icon icon_back_default3x back-icon fl"></i>
			<span class="back-word fl go_back">返回</span>
		</a>
		<h1>发表动态</h1>
		<a href="javascript:void(0)" class="deliver-btn">发布</a>
	</div>
	<div class="deliver-cont">
		<textarea name="" placeholder="快来发表自己的动态吧~" class="deliver-txt"></textarea>
	</div>
	<div class="up_img clearfix">
		<div class="preview fl clearfix img_html">
			<div class="up_img_box fl">
		        <a href="javascript:;" class="add icon fl icon_upload_default3x" title="上传一张新的图片" id="add_upload"></a>
		        <input type="hidden" name="img_url " class="img_url" id="img_url" />
		    </div>
		</div>
	</div>
{/block}
{block name="js"}
{literal}
	<script type="text/javascript" src="/Public/Js/front/front_js/ajaxupload.3.5.js"></script>
	<script type="text/javascript">
		$(function(){
			$(".deliver-header i,.deliver-header span").on("touchstart",function(){
				history.go(-1);
			});
			$(".deliver-btn").on("click",function(){
				if($(".deliver-txt").val()==""){
                    layer.open({
                        content: '请输入发表内容',
                        title: false,
                        btn: ['确定'],
                    });
                    return;
                }
			});
            // 上传图片
            new AjaxUpload("#add_upload", {
	            action: "/Front/uploadHandler",
	            name: "upfile",
	            responseType: "json",
	            onSubmit: function(){
	            	//alert('正在上传');
	                //preview处的图片改为loading图片
	                $('.preview').show();
	                if($("#add_upload").siblings('.preview').find('img').length>=3){
	                    alert("最多上传3张图片");
	                    return false;
	                }
	            },
	            onChange: function(file, extension){
	                if (extension && /^(jpg|png|jpeg|gif)$/.test(extension)) {
	                    return true;
	                }
	                else {
	                    alert('暂不支持该图片格式！');
	                    return false;
	                }
	            },
	            onComplete: function(file, response){
	            //  console.log(response);
	                if (response.status === 0) {
	                    alert(response.msg);
	                }
	                else if (response.status === 1) {
	                    var html;
	                    html='<div class=" fl img_box"><img class="pic-preview" src="'+response.img_url+'"/><div class="del_img"></div></div>';
	                    $('.preview').prepend(html);
	                    // $("#add_upload").siblings('.preview').show();
	                    $("#img_url").val(1);
	                    //删除图片
	                    $(".del_img").on("click",function(){
			                if($(this).parents(".preview").find('img').length==1){
			                	console.log(1);
			                    $(this).parents(".img_html").siblings('.img_url').val('');      
			                }
			                $(this).parent(".img_box").remove();
			            });
	                }
	            }
            });
		});
	</script>
{/literal}
{/block}